<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="index.css" rel="stylesheet">
</head>
<body>
    <div id="app">
        <!-- 头部 -->
      <header class="header">
        <h1>小黑记事本</h1>
        <input placeholder="请输入任务" class="new-todo" v-model="todo_name">
        <button class='add' @click="add">添加任务</button>
      </header>
      <!-- 列表区域 -->
      <section class="main">
        <ul class="todo-list">
            <li class="todo" v-for="(item,index) in list" >
                <div class="view">
                    <span class="index">{{index+1}}.</span><label>{{item.name}}</label>
                    <button class="destroy" @click="del(item.id)"></button>
                </div>
            </li>
        </ul>
          <!-- 统计 -->
      <footer class="footer" v-show="list.length >0">
        <span class="todo-count" >合 计:<strong>{{list.length}}</strong></span>
        <button  class="clear-completed" @click="clear">清空任务</button>
        <!-- 底部 -->
      </footer>
      </section>
      </div>
    <script src="../../vue.js"></script>
    <script>
      const app = new Vue({
        el:'#app',
        data:{
          list:[
            {id:1,name:'跑步二十分钟'},
            {id:2,name:'游泳一百米'},
            {id:3,name:'跳绳一百下'}
          ],
          todo_name:''
        },
        methods:{
          add(){
            this.list.unshift(
              {id:+new Date(),name:this.todo_name}
            )
            this.todo_name=''
          },
          del(id){
            this.list =this.list.filter(item => item.id!=id)
          },
          clear(){
            this.list=[]
          }
        }
      })
    </script>
  
</body>
</html>